/*
 * File:   Whitley.h
 * Author: jcrada
 *
 * Created on 28 April 2011, 10:56 AM
 */

#ifndef ECB_WHITLEY_H
#define	ECB_WHITLEY_H

#include "ecb/base/Problem.h"
namespace ecb {

    /* Source:
     * @incollection{springer-dif.evo,
     Author = {Price, Kenneth and Storn, Rainer M. and Lampinen, Jouni A.},
     title={{Appendix}},
     booktitle = {Differential Evolution: A Practical Approach to Global Optimization},
     series={Natural Computing Series},
     editor={Rozenberg, G. and Bäck, Th. and Eiben, A. E. and Kok, J. N. and Spaink, H. P.},
     publisher = {Springer-Verlag Berlin Heidelberg},
     pages = {513-533},
     year = {2005}
     }
     */
    class Whitley : public Problem {
    public:

        Whitley(const std::string& id = "Whitley", const std::string& name = "Whitley",
                int dimensions = 0, scalar minimum = -100, scalar maximum = 100,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar result = 0;
            for (size_t i = 0; i < x.size(); ++i) {
                scalar sum = 0;
                for (size_t j = 0; j < x.size(); ++j) {
                    scalar a = 100 * (x[i] - x[j] * x[j]) * (x[i] - x[j] * x[j])
                            + (1 - x[j]) * (1 - x[j]);
                    sum += a * a / 4000 - std::cos(a) + 1;
                }
                result += sum;
            }
            return result;
        }
    };



}
#endif	/* ECB_WHITLEY_H */

